<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Person;
use AppBundle\Entity\Note;
class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $case =$em->getRepository('AppBundle:Person')->findAllOrderByName();
        $count = count($case);
        // replace this example code with whatever you need
        return $this->render('AppBundle:Default:index.html.twig',  array('case' => $case,'count'=>$count));
    }
    /**
     *
     * @Route("/search", name="search")
     */
    public function searchAction(Request $request)
    {
        $case1 = array();
        $case2 = array();
        $count1 = array();
        $count2 = array();
        $name = array();
        if ($request->getMethod() == 'POST') {
            $data = $request->request->all();
            $name =$data['search'];
            $em = $this->getDoctrine()->getManager();

            //相似失踪人口
            $case1 =$em->getRepository('AppBundle:Person')->findAlllikeByName($name);
            $count1 = count($case1);
            //相关线索
            $case2 =$em->getRepository('AppBundle:Note')->findAlllikeByName($name);
            $count2 = count($case2);
          }
            // replace this example code with whatever you need
            return $this->render('AppBundle:Default:search.html.twig',array('case1' => $case1,'count1'=>$count1,'case2' => $case2,'count2'=>$count2,'name'=>$name));

    }
    /**
     * 关于
     * @Route("/about", name="about")
     */
    public function aboutAction(Request $request)
    {
        // replace this example code with whatever you need
        return $this->render('AppBundle:Default:about.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);
    }
}
